﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Create.Master" Inherits="System.Web.Mvc.ViewPage<Langben.DAL.Cemetery>" %>

<%@ Import Namespace="Common" %>
<%@ Import Namespace="Models" %>

<asp:Content ID="Content1" ContentPlaceHolderID="CurentPlace" runat="server">
    墓穴管理
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <input id="QuGuid" style="display: none"/>
    <div class="panel datagrid" style="width: auto;">
        <div class="panel-header">
            <div>
                选择园区： 
        <%=Html.DropDownListFor(model => model.Yuan,Models.SysFieldModels.GetArea("Area","Yuan"),"请选择")%>
                <select id="Pian" name="Pian">
                </select>
                <select id="Qu" name="Qu">
                </select>
            </div>
        </div>
        <div class="panel-body" style="height: 100%;">
            <div style="padding: 10px">
                <div id="btnGroup">
 
                    <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-add'" onclick="dingjia()">墓位定价</a>
                </div>
                <div id="CemeteryStr">
                </div>
            </div>
        </div>
    </div>
    <div>
        
        <div id="dingjia" class="easyui-dialog" title="墓位定价" style="padding: 10px"
            data-options="
                iconCls: 'icon-save',
        modal:true ,
                buttons: [{
                    text:'保存',
                    iconCls:'icon-ok',
                    handler:function(){
                        dingjiasave();
                    }
                },{
                    text:'取消',
                    handler:function(){
                         $('#dingjia').dialog('close');
                    }
                }]
            ">
            <table>
                <tr>
                    <td>价格:</td>
                    <td>
                        <input id="price" class="easyui-numberbox" type="text" name="price" data-options="required:true" />
                    </td>
                </tr>


            </table>

        </div>
    </div>

</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="HeadContent" runat="server">
    <style>
        ul {
            clear: both;
        }

        li {
            float: left;
            list-style-type: none;
            width: 60px;
            text-align: center;
            height: 90px;
        }
    </style>
    <script type="text/javascript">
 
        $(function () {
            getPian("#Pian");
            $("#Yuan").change(function () { getPian("#Pian"); });

            getQu("#Qu");
            $("#Pian").change(function () { getQu("#Qu"); });
 
            $('#dingjia').dialog('close');
            $("#Qu").change(function () {
                $("#QuGuid").val($("#Qu").val());

                GetCemeteryString();
            });
 
        });
        function getPian(Pian) {
            $(Pian).empty();
            $("<option></option>")
                .val("")
                .text("请选择")
                .appendTo($(Pian));
            bindAreaDropDownList(Pian, "#Yuan");
            $(Pian).change();
        }

        function getQu(Qu) {
            $(Qu).empty();
            $("<option></option>")
                .val("")
                .text("请选择")
                .appendTo($(Qu));
            bindAreaDropDownList(Qu, "#Pian");
            $(Qu).change();
        }


        function bindAreaDropDownList(id, parentid) {
            if ($(parentid).val() != "") {
                var url = "../Home/GetAreaByParent";
                $.ajaxSetup({ cache: false });
                $.getJSON(url, { id: id.substring(1), parentid: parentid.substring(1), value: $(parentid).val() }, function (data) {
                    if (data == null) {
                        return;
                    }
                    $.each(data, function (i, item) {
                        if (item == null) {
                            return;
                        }
                        $("<option></option>")
                            .val(item["Value"])
                            .text(item["Text"])
                            .appendTo($(id));
                    });
                });
            }
        }
        
        function GetCemeteryString() {
            $.ajax({
                url: "../Cemetery/GetCemeteryString",
                type: "Post",
                data: { quguid: $('#QuGuid').val() },
                dataType: "json",
                success: function (data) {
                    $('#CemeteryStr').html(data);
                    $("input[ id^='cemetery'][type= 'checkbox']").change(function () {
                        var name = $(this).attr("name");
                        if ($(this).attr("checked")) {
                            $("input[name='" + name + "']").attr("checked", true);
                        } else {
                            $("input[name='" + name + "']").attr("checked", false);
                        }
                    });
                }
            });
        }
        function dingjia() {
            var quguid = $('#QuGuid').val();
            if (quguid == "") {
                alert("请选择区域");
                return;
            }

            var arr = [];
            var count = 0;
            $("input:checked").each(function () {
                if ($(this).attr("id") == undefined) {
                    arr.push($(this).val());
                    count++;
                }

            });
            if (count < 1) {
                alert("请至少选择一项。");
                return;
            }

            $('#dingjia').dialog('open');
        }

        function dingjiasave() {
            var price = $('#price').val();
            var arr = [];
            var count = 0;
            $("input:checked").each(function () {
                if ($(this).attr("id") == undefined) {
                    arr.push($(this).val());
                    count++;
                }
            });
            $.messager.confirm('操作提示', "确认设置这 " + count + " 项墓位的价格吗？", function (r) {
                if (r) {
                    $.post("../Cemetery/AjaxDingJia", { query: arr.join(","), price: price }, function (res) {
                        if (res == "OK") {

                            $.messager.alert('操作提示', '设置成功!', 'info');
                            $('#dingjia').dialog('close');
                            GetCemeteryString();
                        }
                        else {
                            if (res == "") {
                                $.messager.alert('操作提示', '设置失败!请查看该数据与其他模块下的信息的关联，或联系管理员。', 'info');

                            }
                            else {
                                $.messager.alert('操作提示', res, 'info');

                            }
                        }
                    });
                }
            });
        }
    </script>
</asp:Content>

